package acm.pta6;

import 左哥算法.ch15并查集.UnionFindSet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class 社交群体 {
    /**
     * 用哈希表记录下每一个爱好是否出现过，如果出现过，记录是哪个人的爱好
     */
    public static void main(String[] args) throws IOException {
        int[] hobby=new int[1001];
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        UnionFindSet<Integer> unionSet=new UnionFindSet<>();
        int n = Integer.parseInt(in.readLine());
        String[] read=null;
        for (int i = 1; i <= n; i++) {
            unionSet.init(i);
            read = in.readLine().split(" ");
            for (int j = 1; j < read.length; j++) {
                int h = Integer.parseInt(read[j]);
                if (hobby[h]!=0){
                    unionSet.union(i,hobby[h]);
                }else {
                    hobby[h]=i;
                }
            }
        }
        StringBuilder sb=new StringBuilder();
        Collection<Integer> sizes = unionSet.getSizeMap().values();
        sizes.stream().sorted((o1, o2) -> o2-o1).forEach(o-> sb.append(o).append(" "));
        System.out.println(sizes.size());
        System.out.println(sb.substring(0,sb.length()-1));
    }
}
